﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace SetEnv
{
    class GetInputValue
    {
        string proxyOverride = string.Empty;

        string proxyServer = string.Empty;

        string proxyEnable = string.Empty;

        string hostPath = string.Empty;

        public string HostPath
        {
            get { return hostPath; }
            set { hostPath = value; }
        }

        public string ProxyEnable
        {
            get { return proxyEnable; }
            set { proxyEnable = value; }
        }

        public string ProxyServer
        {
            get { return proxyServer; }
            set { proxyServer = value; }
        }

        public string ProxyOverride
        {
            get { return proxyOverride; }
            set { proxyOverride = value; }
        }

        private static string envXNLPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Source\Env.xml");

        /// <summary>
        /// Initialize env.xml 
        /// </summary>
        /// <param name="Env"></param>
        public void InitializeEvnData(string Env)
        {
            string XMLpath = envXNLPath;
            XmlDocument xmldoc;
            Env = Env.ToUpper();

            try
            {
                xmldoc = new XmlDocument();
                xmldoc.Load(XMLpath);
                if (xmldoc != null)
                {
                    XmlNode envNodeProOver = xmldoc.SelectSingleNode(@"/Env" + "/" + Env + "/ProxyOverride");
                    this.proxyOverride = envNodeProOver.InnerText;
                    XmlNode envNodeServer = xmldoc.SelectSingleNode(@"/Env" + "/" + Env + "/ProxyServer");
                    this.proxyServer = envNodeServer.InnerText;
                    XmlNode nodeProxyEnable = xmldoc.SelectSingleNode(@"/Env" + "/" + Env + "/ProxyEnable");
                    this.proxyEnable = nodeProxyEnable.InnerText;
                    XmlNode nodeHostPath = xmldoc.SelectSingleNode(@"/Env" + "/" + Env + "/HostPath");
                    this.hostPath = nodeHostPath.InnerText;
                }
            }
            catch (System.NullReferenceException e)
            {
                Console.WriteLine("Failed to load XML: Plese keep your element inconsisting with Env.xml. {0}", e);

            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to load XML: ({0})", XMLpath);
                throw (e);

            }
        }

    }
}
